package com.gmail.dengtao.joe.group.transport;

import com.gmail.dengtao.joe.group.interceptor.InterceptorStack;
import com.gmail.dengtao.joe.group.member.Member;

public interface ChannelSender {

	/**
     * Start listening for incoming messages on the host/port
	 * @param senderLock 
     * @throws java.io.IOException
     * @since 1.0
     */
    public void start(Object senderLock) throws Exception;

    /**
     * Stop listening for messages
     * @since 1.0
     */
    public void stop() throws Exception;
	
	/**
	 * connect to target member.
	 * @param target
	 * @throws Exception
	 * @since 1.0
	 */
    public void connect(Member target) throws Exception;

	/**
	 * Get idle time for write in seconds.
	 * @return
	 * @since 1.0
	 */
	public int getIdleTimeForWrite();

	/**
	 * Set idle time for write in seconds, you should call this method before {@link ChannelReceiver#start()}.
	 * @param idleTimeForWrite
	 * @since 1.0
	 */
	public void setIdleTimeForWrite(int idleTimeForWrite);
	
	/**
	 * Get current selector's timeout
	 * @return current selector's timeout in ms
	 * @since 1.0
	 */
	public int getSelectTimeout();

	/**
	 * Set selector's timeout, you should call this method before {@link ChannelReceiver#start()}.
	 * @param selectTimeout ms
	 * @since 1.0
	 */
	public void setSelectTimeout(int selectTimeout);

	public InterceptorStack getInterceptorStack();

	public void setInterceptorStack(InterceptorStack interceptorStack);
	
	/**
     * Allocates a new byte buffer. 
     * The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined. It will have a backing array, and its array offset will be zero.
     * you should call this method before {@link ChannelReceiver#start()}.
     * @param sendBufferSize
     * @since 1.0
     */
	public void setSendBufferSize(int i);

	public void send(Member target, Object data);

}